<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Model\Position;
use App\Model\Bistro;
use App\Model\Product;
use App\Transformers\ProductTransformer;

use App\Transformers\PositionTransformer;
use App\Http\Controllers\Controller;

class PositionController extends Controller
{
    //

    public function index($id) {
        $bistro = Bistro::findorfail($id);

        $positions = Position::where('bistro_id', $bistro->id)->paginate(10);
        $data['data'] = [
            'positions' => $this->factalPaginator($positions, new PositionTransformer())
        ];
        return $this->apiSuccess($data);
    }


    public function searchWithQrcode(Request $request) {
        $qr_code = $request->input('qr_code');
        $postion = Position::where('qr_code', $qr_code)->first();

        $products = Product::where('id', $postion->bistro_id)->paginate(10);
        $data['data'] = [
            'products' => $this->factalPaginator($products, new ProductTransformer())
        ];

        return $this->apiSuccess($data);
    }
}
